home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / basics / videoframetogworld / getfile.c next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  7.2 KB  |  191 lines

  1. /*
  2.     File:        GetFile.c
  3.     
  4.     Description: VideoFrameToGWorld is an example of decompressing frames from a video track
  5.                  into an offscreen buffer so the pixels can be manipulated at a later time.
  6.  
  7.     Author:        based on code from QTShell sample
  8.  
  9.     Copyright:     © Copyright 2000 Apple Computer, Inc. All rights reserved.
  10.     
  11.     Disclaimer:    IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
  12.                 ("Apple") in consideration of your agreement to the following terms, and your
  13.                 use, installation, modification or redistribution of this Apple software
  14.                 constitutes acceptance of these terms.  If you do not agree with these terms,
  15.                 please do not use, install, modify or redistribute this Apple software.
  16.  
  17.                 In consideration of your agreement to abide by the following terms, and subject
  18.                 to these terms, Apple grants you a personal, non-exclusive license, under Apple’s
  19.                 copyrights in this original Apple software (the "Apple Software"), to use,
  20.                 reproduce, modify and redistribute the Apple Software, with or without
  21.                 modifications, in source and/or binary forms; provided that if you redistribute
  22.                 the Apple Software in its entirety and without modifications, you must retain
  23.                 this notice and the following text and disclaimers in all such redistributions of
  24.                 the Apple Software.  Neither the name, trademarks, service marks or logos of
  25.                 Apple Computer, Inc. may be used to endorse or promote products derived from the
  26.                 Apple Software without specific prior written permission from Apple.  Except as
  27.                 expressly stated in this notice, no other rights or licenses, express or implied,
  28.                 are granted by Apple herein, including but not limited to any patent rights that
  29.                 may be infringed by your derivative works or by other works in which the Apple
  30.                 Software may be incorporated.
  31.  
  32.                 The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
  33.                 WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
  34.                 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  35.                 PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
  36.                 COMBINATION WITH YOUR PRODUCTS.
  37.  
  38.                 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
  39.                 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  40.                 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  41.                 ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
  42.                 OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
  43.                 (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
  44.                 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45.                 
  46.     Change History (most recent first): <1> 4/1/00 initial release
  47.  
  48. */
  49.  
  50. #include "VideoFrameToGWorld.h"
  51.  
  52. //////////
  53. //
  54. // GetOneFileWithPreview
  55. // Display the appropriate file-opening dialog box, with an optional QuickTime preview pane. If the user
  56. // selects a file, return information about it using the theFSSpecPtr parameter.
  57. //
  58. // Note that both StandardGetFilePreview and NavGetFile use the function specified by theFilterProc as a
  59. // file filter. This framework always passes NULL in the theFilterProc parameter. If you use this function
  60. // in your own code, keep in mind that on Windows the function specifier must be of type FileFilterUPP and 
  61. // on Macintosh it must be of type NavObjectFilterUPP. (You can use the QTFrame_GetFileFilterUPP to create
  62. // a function specifier of the appropriate type.) Also keep in mind that Navigation Services expects a file 
  63. // filter function to return true if a file is to be displayed, while the Standard File Package expects the
  64. // filter to return false if a file is to be displayed.
  65. //
  66. //////////
  67. OSErr GetOneFileWithPreview (short theNumTypes, TypeListPtr theTypeList, FSSpecPtr theFSSpecPtr, void *theFilterProc)
  68. {
  69.     
  70. #if TARGET_OS_WIN32
  71.     StandardFileReply    myReply;
  72. #endif
  73. #if TARGET_OS_MAC
  74.     NavReplyRecord        myReply;
  75.     NavDialogOptions    myDialogOptions;
  76.     NavTypeListHandle    myOpenList = NULL;
  77.     NavEventUPP            myEventUPP = NewNavEventUPP(HandleNavEvent);
  78. #endif
  79.     OSErr                myErr = noErr;
  80.     
  81.     if (theFSSpecPtr == NULL)
  82.         return(paramErr);
  83.  
  84. #if TARGET_OS_WIN32
  85.     // prompt the user for a file
  86.     StandardGetFilePreview((FileFilterUPP)theFilterProc, theNumTypes, (ConstSFTypeListPtr)theTypeList, &myReply);
  87.     if (!myReply.sfGood)
  88.         return(userCanceledErr);
  89.     
  90.     // make an FSSpec record
  91.     myErr = FSMakeFSSpec(myReply.sfFile.vRefNum, myReply.sfFile.parID, myReply.sfFile.name, theFSSpecPtr);
  92. #endif
  93.  
  94. #if TARGET_OS_MAC
  95.     // specify the options for the dialog box
  96.     NavGetDefaultDialogOptions(&myDialogOptions);
  97.     myDialogOptions.dialogOptionFlags -= kNavNoTypePopup;
  98.     myDialogOptions.dialogOptionFlags -= kNavAllowMultipleFiles;
  99.     BlockMoveData(kApplicationName, myDialogOptions.clientName, kApplicationName[0] + 1);
  100.     
  101.     // create a handle to an 'open' resource
  102.     myOpenList = (NavTypeListHandle)CreateOpenHandle(kApplicationSignature, theNumTypes, theTypeList);
  103.     if (myOpenList != NULL)
  104.         HLock((Handle)myOpenList);
  105.     
  106.     // prompt the user for a file
  107.     myErr = NavGetFile(NULL, &myReply, &myDialogOptions, myEventUPP, NULL, (NavObjectFilterUPP)theFilterProc, myOpenList, NULL);
  108.     if ((myErr == noErr) && myReply.validRecord) {
  109.         AEKeyword        myKeyword;
  110.         DescType        myActualType;
  111.         Size            myActualSize = 0;
  112.         
  113.         // get the FSSpec for the selected file
  114.         if (theFSSpecPtr != NULL)
  115.             myErr = AEGetNthPtr(&(myReply.selection), 1, typeFSS, &myKeyword, &myActualType, theFSSpecPtr, sizeof(FSSpec), &myActualSize);
  116.  
  117.         NavDisposeReply(&myReply);
  118.     }
  119.     
  120.     if (myOpenList != NULL) {
  121.         HUnlock((Handle)myOpenList);
  122.         DisposeHandle((Handle)myOpenList);
  123.     }
  124.     
  125.     DisposeNavEventUPP(myEventUPP);
  126. #endif
  127.  
  128.     return(myErr);
  129. }
  130.  
  131. //////////
  132. //
  133. // CreateOpenHandle
  134. // Get the 'open' resource or dynamically create a NavTypeListHandle.
  135. //
  136. //////////
  137. Handle CreateOpenHandle (OSType theApplicationSignature, short theNumTypes, TypeListPtr theTypeList)
  138. {
  139.     Handle            myHandle = NULL;
  140.     
  141.     // see if we have an 'open' resource...
  142.     myHandle = Get1Resource('open', 128);
  143.     if ( myHandle != NULL && ResError() == noErr ) {
  144.         DetachResource( myHandle );
  145.         return myHandle;
  146.     } else {
  147.         myHandle = NULL;
  148.     }
  149.     
  150.     // nope, use the passed in types and dynamically create the NavTypeList
  151.     if (theTypeList == NULL)
  152.         return myHandle;
  153.     
  154.     if (theNumTypes > 0) {
  155.         myHandle = NewHandle(sizeof(NavTypeList) + (theNumTypes * sizeof(OSType)));
  156.         if (myHandle != NULL) {
  157.             NavTypeListHandle     myOpenResHandle    = (NavTypeListHandle)myHandle;
  158.             
  159.             (*myOpenResHandle)->componentSignature = theApplicationSignature;
  160.             (*myOpenResHandle)->osTypeCount = theNumTypes;
  161.             BlockMoveData(theTypeList, (*myOpenResHandle)->osType, theNumTypes * sizeof(OSType));
  162.         }
  163.     }
  164.     
  165.     return myHandle;
  166. }
  167.  
  168. //////////
  169. //
  170. // HandleNavEvent
  171. // A callback procedure that handles events while a Navigation Service dialog box is displayed.
  172. //
  173. //////////
  174. PASCAL_RTN void HandleNavEvent(NavEventCallbackMessage theCallBackSelector, NavCBRecPtr theCallBackParms, void *theCallBackUD)
  175. {
  176. #pragma unused(theCallBackUD)
  177.     WindowReference        myWindow = NULL;    
  178.     
  179.     if (theCallBackSelector == kNavCBEvent) {
  180.         switch (theCallBackParms->eventData.eventDataParms.event->what) {
  181.             case updateEvt:
  182. #if TARGET_OS_MAC
  183.                 // Handle Update Event
  184. #endif
  185.                 break;
  186.             case nullEvent:
  187.                 // Handle Null Event
  188.                 break;
  189.         }
  190.     }
  191. }